#include<iostream>
#include<algorithm>
using namespace std;
const int N = 3e5 + 10;
int q[N];
int s[N];
int n, m;
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		s[i] += s[i - 1];
	}
	int hh = 0, tt = 0;
	int ans = -1e9;
	for (int i = 1; i <= n; i++) {
		if (q[hh] + m < i) hh++;
		ans = max(ans ,s[i] - s[q[hh]]);
		while (hh <= tt && s[q[tt]] >= s[i]) {
			tt--;
		}
		q[++tt] = i;
	}
	cout << ans << endl;
	return 0;
}